#include <my_header.h>
/*Usage: ./04_cpMfile src dest  */
int main(int argc, char *argv[]){
    ARGS_CHECK(argc,3);
    int fds = open(argv[1],O_RDONLY);
    ERROR_CHECK(fds, -1,"open src");
    printf("fds = %d\n",fds);
    int fdw = open(argv[2],O_RDWR | O_CREAT |O_TRUNC, 0666);
    ERROR_CHECK(fdw, -1 ,"open dest");
    printf("fdw = %d\n",fdw);                    
    char buff[1024] = { 0 };
    int read_count = 0;
    //循环复制文件内容，当read_count等于0说明复制到了文件末尾
    //当read_count返回为-1说明是错误退出
    while((read_count = read(fds,buff,sizeof(buff))) > 0){
        
        write(fdw,buff,read_count);
    }
    //设置一个错误判断，看看循环退出是不是read错误退出
    ERROR_CHECK(read_count, -1, "read error");
    close(fds);
    close(fdw);
    return 0;
}


